From dae65b7c622a3955c9af871735a48617617831bc Mon Sep 17 00:00:00 2001 From: William Jon McCann Date: Mon, 6 Jan 2014 13:46:12 -0500 Subject: [PATCH] tests: add menu alignments to the menubutton test https://bugzilla.gnome.org/show_bug.cgi?id=720939 --- tests/testmenubutton.c | 96 +++++++++++++++++++++++++++++++++++------- 1 file changed, 80 insertions(+), 16 deletions(-) diff --git a/tests/testmenubutton.c b/tests/testmenubutton.c index 48e4831270..fc3e1e96cf 100644 --- a/tests/testmenubutton.c +++ b/tests/testmenubutton.c @@ -1,15 +1,49 @@ #include #include "prop-editor.h" +#define INITIAL_HALIGN GTK_ALIGN_START +#define INITIAL_VALIGN GTK_ALIGN_START + +static GList *menubuttons = NULL; + +static void +horizontal_alignment_changed (GtkComboBox *box) +{ + GtkAlign alignment = gtk_combo_box_get_active (box); + GList *l; + + for (l = menubuttons; l != NULL; l = l->next) { + GtkMenu *popup = gtk_menu_button_get_popup (GTK_MENU_BUTTON (l->data)); + if (popup != NULL) + gtk_widget_set_halign (GTK_WIDGET (popup), alignment); + } +} + +static void +vertical_alignment_changed (GtkComboBox *box) +{ + GtkAlign alignment = gtk_combo_box_get_active (box); + GList *l; + + for (l = menubuttons; l != NULL; l = l->next) { + GtkMenu *popup = gtk_menu_button_get_popup (GTK_MENU_BUTTON (l->data)); + if (popup != NULL) + gtk_widget_set_valign (GTK_WIDGET (popup), alignment); + } +} + int main (int argc, char **argv) { GtkWidget *window; GtkWidget *button; GtkWidget *grid; GtkWidget *entry; + GtkWidget *label; + GtkWidget *combo; GtkWidget *menu_widget; GtkAccelGroup *accel_group; guint i; + guint row = 0; GMenu *menu; gtk_init (&argc, &argv); @@ -26,17 +60,48 @@ int main (int argc, char **argv) accel_group = gtk_accel_group_new (); gtk_window_add_accel_group (GTK_WINDOW (window), accel_group); + /* horizontal alignment */ + label = gtk_label_new ("Horizontal Alignment:"); + gtk_widget_show (label); + gtk_grid_attach (GTK_GRID (grid), label, 0, row++, 1, 1); + + combo = gtk_combo_box_text_new (); + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "Fill"); + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "Start"); + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "End"); + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "Center"); + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "Baseline"); + gtk_combo_box_set_active (GTK_COMBO_BOX (combo), INITIAL_HALIGN); + gtk_widget_show (combo); + gtk_grid_attach_next_to (GTK_GRID (grid), combo, label, GTK_POS_RIGHT, 1, 1); + g_signal_connect (G_OBJECT (combo), "changed", + G_CALLBACK (horizontal_alignment_changed), menubuttons); + + /* vertical alignment */ + label = gtk_label_new ("Vertical Alignment:"); + gtk_widget_show (label); + gtk_grid_attach (GTK_GRID (grid), label, 0, row++, 1, 1); + + combo = gtk_combo_box_text_new (); + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "Fill"); + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "Start"); + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "End"); + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "Center"); + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "Baseline"); + gtk_combo_box_set_active (GTK_COMBO_BOX (combo), INITIAL_HALIGN); + gtk_widget_show (combo); + gtk_grid_attach_next_to (GTK_GRID (grid), combo, label, GTK_POS_RIGHT, 1, 1); + g_signal_connect (G_OBJECT (combo), "changed", + G_CALLBACK (vertical_alignment_changed), menubuttons); + /* Button next to entry */ entry = gtk_entry_new (); - gtk_grid_attach (GTK_GRID (grid), - entry, - 0, 0, - 1, 1); + gtk_grid_attach (GTK_GRID (grid), entry, 0, row++, 1, 1); button = gtk_menu_button_new (); - gtk_grid_attach (GTK_GRID (grid), - button, - 1, 0, - 1, 1); + gtk_widget_set_halign (button, GTK_ALIGN_START); + + gtk_grid_attach_next_to (GTK_GRID (grid), button, entry, GTK_POS_RIGHT, 1, 1); + menubuttons = g_list_prepend (menubuttons, button); /* Button with GtkMenu */ menu_widget = gtk_menu_new (); @@ -61,11 +126,10 @@ int main (int argc, char **argv) gtk_widget_show_all (menu_widget); button = gtk_menu_button_new (); + gtk_widget_set_halign (button, GTK_ALIGN_START); + menubuttons = g_list_prepend (menubuttons, button); gtk_menu_button_set_popup (GTK_MENU_BUTTON (button), menu_widget); - gtk_grid_attach (GTK_GRID (grid), - button, - 1, 1, - 1, 1); + gtk_grid_attach (GTK_GRID (grid), button, 1, row++, 1, 1); gtk_widget_show (create_prop_editor (G_OBJECT (button), 0)); /* Button with GMenuModel */ @@ -81,12 +145,12 @@ int main (int argc, char **argv) g_object_unref (item); g_free (label); } + button = gtk_menu_button_new (); + gtk_widget_set_halign (button, GTK_ALIGN_START); + menubuttons = g_list_prepend (menubuttons, button); gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (button), G_MENU_MODEL (menu)); - gtk_grid_attach (GTK_GRID (grid), - button, - 1, 2, - 1, 1); + gtk_grid_attach (GTK_GRID (grid), button, 1, row++, 1, 1); gtk_widget_show_all (window); -- 2.30.2